<?php
$pageSize			=		MEDIA_PAGESIZE;
$pageListSize		=		MEDIA_PAGELISTSIZE;
$page 				= 		getPage('page');

$user_id			=		(int)getQuery('user_id');

$tagsUrl 			= 		$_GET['tag'] ? $_GET['tag'] : $_GET['id'] ; //$_GET['tag']; 优化静态化


$searchTag 			= 		$_GET['searchTag'];
$type 				=		$_GET['type'];
$searchTag 			== 		'' ? '' :  $like = '( `name` like "%'. $searchTag .'%"" )';

$order				=		getQuery('order') ;
if($order == '')	$order = 'id';
$fromType			=		getQuery('fromType') ;

$tagMenus = explode('|',$tagsUrl); 
 
$where = '';
$whereTagCurrent = '';
$like = '';
$i = 0;
foreach($tagMenus as $tMs){
	$tM = explode('!',$tMs);
	if($tM[1]=='') continue;
	$ids = explode(',',$tM[1]);
	
	foreach( $ids as $id){
		$or = $i == 0 ? '' : ' or ';
		$where .= $or .'( `tag` =  '.$tM[0].' and `tagMenu` ='.$id .' )';
		$whereTagCurrent .= $or .'( `parentId` =  '.$tM[0].' and `id` ='.$id .' )';
		$i++;
	}	
}

$where 				== '' ? '' : $where  = ' WHERE ' . $where ; 
$whereTagCurrent	== '' ? '' : $whereTagCurrent  = ' WHERE ' . $whereTagCurrent ; 

$sqlCount = 'SELECT distinct parentId FROM `'. DB_PRE.'filetag` '. $where .' ORDER BY `'.$order.'` DESC';//
$sql= $sqlCount .' limit '.(($page-1)*$pageSize).','.$pageSize ;
$tagsCount = $dbs -> select($sqlCount);
$tags = $dbs -> select($sql);
 

//single tag
$sql = 'SELECT * FROM `'. DB_PRE.'tag_menu` '. $whereTagCurrent;//
$tagCurrent = $dbs -> select($sql);



$total = count($tagsCount) ;
$totalPages = ceil(count($tagsCount) / $pageSize);

?>